//
//  ContactInformationVC.m
//  MRBang
//
//  Created by 铅笔 on 16/4/19.
//  Copyright © 2016年 杭州易网新科技. All rights reserved.
//

#import "ContactInformationVC.h"
#import "PickViewSelect.h"
#import "SubmitSuccessfullyVC.h"

@interface ContactInformationVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,pickViewStrDelegate>

{
    NSMutableArray *array_contentFirst,*array_contentSecond;//联系人组一组／二组
    
    int record_section;//记录点击的是哪一个 关系选择
}

@property (nonatomic,strong) UITableView *tableView_fillInfo;

@property(nonatomic,strong)PickViewSelect *pickView;

@end

@implementation ContactInformationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"联系人资料";
    self.view.backgroundColor = COLOR_EVERYVIEWBG;
    
    //联系人组 赋出初始值
    array_contentFirst = [@[@"填写",@"兄弟姐妹",@"填写",@"填写"] mutableCopy];
    array_contentSecond = [@[@"填写",@"兄弟姐妹",@"填写",@"填写"] mutableCopy];

    [self initWithContactInformationVCSubviews];
    
    //注册键盘通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
     record_section = 3;
}

#pragma mark --- 创建所有视图
- (void) initWithContactInformationVCSubviews
{
    self.tableView_fillInfo = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-93*PROPORTION_WIDTH-20) style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView_fillInfo];
    self.tableView_fillInfo.dataSource = self;
    self.tableView_fillInfo.delegate = self;
    self.tableView_fillInfo.showsVerticalScrollIndicator = NO;
    self.tableView_fillInfo.separatorStyle =UITableViewCellSeparatorStyleNone;
    self.tableView_fillInfo.backgroundColor = COLOR_EVERYVIEWBG;
    
    // button
    UIButton *button_nextAction = [[UIButton alloc] initWithFrame:CGRectMake(48*PROPORTION_WIDTH,kScreenHeight-93*PROPORTION_WIDTH-10,kScreenWidth - 48*PROPORTION_WIDTH*2, 93*PROPORTION_WIDTH)];
    [self.view addSubview:button_nextAction];
    
    [button_nextAction setBackgroundImage:[UIImage imageNamed:@"button_submit"] forState:UIControlStateNormal];
    
    [button_nextAction addTarget:self action:@selector(doSubmitAction) forControlEvents:UIControlEventTouchUpInside];
}

#pragma  mark ----UITableViewDataSource
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellFillInInformationID = @"cellFillInInformationID";
    
    UITableViewCell *cell_fillInfo = [tableView cellForRowAtIndexPath:indexPath];
    if (cell_fillInfo==nil) {
        cell_fillInfo = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellFillInInformationID];
    }
    
    UIView *view_line = [[UIView alloc] initWithFrame:CGRectMake(27*PROPORTION_WIDTH, cell_fillInfo.height-1, kScreenWidth, 1.0)];
    [cell_fillInfo.contentView addSubview:view_line];
    view_line.backgroundColor = [BaseViewController colorWithHexString:@"#EEEFF1"];
    
    cell_fillInfo.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSArray *array_title;
    if (indexPath.section==0) {
        array_title = @[@"联系人  ①  资料",@"*中文姓名",@"*关系",@"*住宅电话",@"*移动电话"];
    }
    if (indexPath.section==1) {
         array_title = @[@"联系人  ②  资料",@"*中文姓名",@"*关系",@"*住宅电话",@"*移动电话"];
    }

    UILabel *label_leftTitle = [[UILabel alloc] initWithFrame:CGRectMake(27*PROPORTION_WIDTH, 31*PROPORTION_WIDTH, 228*PROPORTION_WIDTH, 20)];
    [cell_fillInfo addSubview:label_leftTitle];
    
    label_leftTitle.font = [UIFont systemFontOfSize:30*PROPORTION_WIDTH];
    label_leftTitle.textColor = [BaseViewController colorWithHexString:@"#666666"];
    label_leftTitle.text = array_title[indexPath.row];
    
    NSRange range1 = [label_leftTitle.text rangeOfString: @"*"];
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString: label_leftTitle.text];
    [attribute addAttributes: @{NSForegroundColorAttributeName:[UIColor redColor]}range: range1];
    
    [attribute addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30*PROPORTION_WIDTH] range:range1];
    [label_leftTitle setText: label_leftTitle.text];
    [label_leftTitle setAttributedText: attribute];

    
    //右侧 文字
    UILabel *label_rightContent = [[UILabel alloc] initWithFrame:CGRectMake(label_leftTitle.right+5, 22*PROPORTION_WIDTH, 448*PROPORTION_WIDTH, 20)];
    [cell_fillInfo addSubview:label_rightContent];
    label_rightContent.font = [UIFont systemFontOfSize:30*PROPORTION_WIDTH];
    label_rightContent.textColor = [BaseViewController colorWithHexString:@"#AAAAAA"];
    
    //右侧剪头
    if (indexPath.row==2) {
        UIButton *button_rightArrow = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth-30, 12, 20, 20)];
        [cell_fillInfo.contentView addSubview:button_rightArrow];
        [button_rightArrow setImage:[UIImage imageNamed:@"return_right"] forState:UIControlStateNormal];
    }
    if (indexPath.section==0) {
        if (indexPath.row==2&&indexPath.row!=0) {
            label_rightContent.text = array_contentFirst[indexPath.row-1];
            
            if (self.dic_pathPersonInfo[@"contacttype"]) {
                
                NSString *str_contacttype;
                int contacttype = [self.dic_pathPersonInfo[@"contacttype"]intValue];
                
                if (contacttype==1) {
                    str_contacttype = @"配偶";
                }
                if (contacttype==2) {
                    str_contacttype = @"子女";
                }
                if (contacttype==3) {
                    str_contacttype = @"父母";
                }
                if (contacttype==4) {
                    str_contacttype = @"兄弟姐妹";
                }
                if (contacttype==5) {
                    str_contacttype = @"其他";
                }
                
                label_rightContent.text = [NSString stringWithFormat:@"%@",str_contacttype];

            }
        }
        if (indexPath.row!=2&&indexPath.row!=0) {
            //uitextField
            UITextField *textField_finll = [[UITextField alloc] initWithFrame:label_rightContent.frame];
            [cell_fillInfo addSubview:textField_finll];
            textField_finll.font = [UIFont systemFontOfSize:30*PROPORTION_WIDTH];
            textField_finll.textColor = [BaseViewController colorWithHexString:@"#AAAAAA"];
            textField_finll.tag = indexPath.row+10;
            textField_finll.delegate = self;
            textField_finll.placeholder = array_contentFirst[indexPath.row-1];
            
            if (indexPath.row==1) {
                if ([self.dic_pathPersonInfo[@"contactname"] length]!=0) {
                    textField_finll.text = [NSString stringWithFormat:@"%@",self.dic_pathPersonInfo[@"contactname"]];
                    
                    [array_contentFirst replaceObjectAtIndex:indexPath.row-1 withObject:self.dic_pathPersonInfo[@"contactname"]];
                }
            }
            if (indexPath.row==3) {
                if ([self.dic_pathPersonInfo[@"contacttel"] length]!=0) {
                    textField_finll.text = [NSString stringWithFormat:@"%@",self.dic_pathPersonInfo[@"contacttel"]];
                    
                     [array_contentFirst replaceObjectAtIndex:indexPath.row-1 withObject:self.dic_pathPersonInfo[@"contacttel"]];
                }

            }
            if (indexPath.row==4) {
                if ([self.dic_pathPersonInfo[@"contactmobile"] length]!=0) {
                    textField_finll.text = [NSString stringWithFormat:@"%@",self.dic_pathPersonInfo[@"contactmobile"]];
                    [array_contentFirst replaceObjectAtIndex:indexPath.row-1 withObject:self.dic_pathPersonInfo[@"contactmobile"]];
                }
            }
        }
    }
    
    if (indexPath.section==1) {
        if (indexPath.row==2&&indexPath.row!=0) {
            label_rightContent.text = array_contentSecond[indexPath.row-1];
        
            if (self.dic_pathPersonInfo[@"contacttype1"]) {
                NSString *str_contacttype;
                int contacttype = [self.dic_pathPersonInfo[@"contacttype1"]intValue];
                
                if (contacttype==1) {
                    str_contacttype = @"配偶";
                }
                if (contacttype==2) {
                    str_contacttype = @"子女";
                }
                if (contacttype==3) {
                    str_contacttype = @"父母";
                }
                if (contacttype==4) {
                    str_contacttype = @"兄弟姐妹";
                }
                if (contacttype==5) {
                    str_contacttype = @"其他";
                }
                
                
                label_rightContent.text = [NSString stringWithFormat:@"%@",str_contacttype];
            }
        }
        
        if (indexPath.row!=2&&indexPath.row!=0) {
            //uitextField
            UITextField *textField_finll = [[UITextField alloc] initWithFrame:label_rightContent.frame];
            [cell_fillInfo addSubview:textField_finll];
            textField_finll.font = [UIFont systemFontOfSize:30*PROPORTION_WIDTH];
            textField_finll.textColor = [BaseViewController colorWithHexString:@"#AAAAAA"];
            textField_finll.tag = indexPath.row+20;
            textField_finll.delegate = self;
            textField_finll.placeholder = array_contentSecond[indexPath.row-1];
            
            if (indexPath.row==1) {
                if ([self.dic_pathPersonInfo[@"contactname1"] length]!=0) {
                    textField_finll.text = [NSString stringWithFormat:@"%@",self.dic_pathPersonInfo[@"contactname1"]];
                    
                    [array_contentSecond replaceObjectAtIndex:indexPath.row-1 withObject:self.dic_pathPersonInfo[@"contactname1"]];
                }
            }
            if (indexPath.row==3) {
                if ([self.dic_pathPersonInfo[@"contacttel1"] length]!=0) {
                    textField_finll.text = [NSString stringWithFormat:@"%@",self.dic_pathPersonInfo[@"contacttel1"]];
                    
                    [array_contentSecond replaceObjectAtIndex:indexPath.row-1 withObject:self.dic_pathPersonInfo[@"contacttel1"]];
                }
                
            }
            if (indexPath.row==4) {
                if ([self.dic_pathPersonInfo[@"contactmobile1"] length]!=0) {
                    textField_finll.text = [NSString stringWithFormat:@"%@",self.dic_pathPersonInfo[@"contactmobile1"]];
                    
                     [array_contentSecond replaceObjectAtIndex:indexPath.row-1 withObject:self.dic_pathPersonInfo[@"contactmobile1"]];
                }
            }
        }
    }
    
    return cell_fillInfo;
    
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==2) {
        NSArray *array_allData = @[@"配偶",@"子女",@"父母",@"兄弟姐妹",@"其他"];
        
        _pickView =[[PickViewSelect alloc]initWithDataArr:array_allData andRowIndex:(int)indexPath.row];
        _pickView.delegate = self;
        [self.view addSubview:_pickView];
    }
    
    record_section = indexPath.section;
    
    //键盘退出
    [self commentTableViewTouchInSide];
}

- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10.0*PROPORTION_WIDTH;
}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}

//提交 按钮执行事件
- (void) doSubmitAction
{
//    if (!self.dic_pathPersonInfo && ([array_contentFirst containsObject:@"填写"] || [array_contentSecond containsObject:@"填写"])) {
//        [UIView showAlertMsg:@"请完善信息"];
//        return;
//    }
    
//if (([array_contentFirst containsObject:@"填写"] || [array_contentSecond containsObject:@"填写"])) {
//    [UIView showAlertMsg:@"请完善信息"];
//    return;
//}

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    //提交数据信息
    [self dataSourceRequestSubmitMessage];
}

//文字内容替换
- (void) textFieldDidEndEditing:(UITextField *)textField
{
    if (record_section==0) {
        
        if (textField.tag == 11 && textField.text.length!=0) {
            [self.dic_pathPersonInfo setObject:textField.text forKey:@"contactname"];
        }
        if (textField.tag == 13 && textField.text.length!=0) {
            [self.dic_pathPersonInfo setObject:textField.text forKey:@"contacttel"];
        }
        if (textField.tag == 14 && textField.text.length!=0) {
            [self.dic_pathPersonInfo setObject:textField.text forKey:@"contactmobile"];
        }
        
    }
    
    if (record_section==1) {
        if (textField.tag == 21 && textField.text.length!=0) {
            [self.dic_pathPersonInfo setObject:textField.text forKey:@"contactname1"];
        }
        if (textField.tag == 23 && textField.text.length!=0) {
            [self.dic_pathPersonInfo setObject:textField.text forKey:@"contacttel1"];
        }
        if (textField.tag == 24 && textField.text.length!=0) {
            [self.dic_pathPersonInfo setObject:textField.text forKey:@"contactmobile1"];
        }

//        [array_contentSecond replaceObjectAtIndex:textField.tag-21 withObject:textField.text];
    }
    
     [self.tableView_fillInfo reloadData];
}

- (void) textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField.tag==11||textField.tag==13||textField.tag==14) {
        record_section = 0;
    }
    if (textField.tag==21||textField.tag==23||textField.tag==24) {
        record_section = 1;
    }
}

#pragma mark -- picker delegate
- (void) pickViewdelegateWith:(NSString *)messStr andRow:(int)rowIndex andSelectecRow:(int)selectedRow
{
    if (record_section==0) {
        
        int contacttype = 0;
        
        if ([messStr isEqualToString:@"配偶"]) {
            contacttype = 1;
        }
        if ([messStr isEqualToString:@"子女"]) {
            contacttype = 2;
        }
        if ([messStr isEqualToString:@"父母"]) {
            contacttype = 3;
        }
        if ([messStr isEqualToString:@"兄弟姐妹"]) {
            contacttype = 4;
        }
        if ([messStr isEqualToString:@"其他"]) {
            contacttype = 5;
        }

        [self.dic_pathPersonInfo setObject:[NSNumber numberWithInt:contacttype] forKey:@"contacttype"];
//         [array_contentFirst replaceObjectAtIndex:rowIndex-1 withObject:messStr];
    }
    if (record_section == 1) {
        int contacttype = 0;
        
        if ([messStr isEqualToString:@"配偶"]) {
            contacttype = 1;
        }
        if ([messStr isEqualToString:@"子女"]) {
            contacttype = 2;
        }
        if ([messStr isEqualToString:@"父母"]) {
            contacttype = 3;
        }
        if ([messStr isEqualToString:@"兄弟姐妹"]) {
            contacttype = 4;
        }
        if ([messStr isEqualToString:@"其他"]) {
            contacttype = 5;
        }

        [self.dic_pathPersonInfo setObject:[NSNumber numberWithInt:contacttype] forKey:@"contacttype1"];
//        [array_contentSecond replaceObjectAtIndex:rowIndex-1 withObject:messStr];
    }
    [self.tableView_fillInfo reloadData];
}

#pragma mark  --- 点击tableView 收回键盘
- (void)commentTableViewTouchInSide
{
    UITextField *textField_temp11 = (UITextField *)[self.view viewWithTag:11];
    
    [textField_temp11 resignFirstResponder];
    
    UITextField *textField_temp13 = (UITextField *)[self.view viewWithTag:13];
    
    [textField_temp13 resignFirstResponder];
    
    UITextField *textField_temp14 = (UITextField *)[self.view viewWithTag:14];
    
    [textField_temp14 resignFirstResponder];
    
    
    UITextField *textField_temp21 = (UITextField *)[self.view viewWithTag:21];
    
    [textField_temp21 resignFirstResponder];
    
    UITextField *textField_temp23 = (UITextField *)[self.view viewWithTag:23];
    
    [textField_temp23 resignFirstResponder];
    
    UITextField *textField_temp24 = (UITextField *)[self.view viewWithTag:24];
    
    [textField_temp24 resignFirstResponder];
}

- (void) touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

#pragma mark ---网络数据请求  发送填写的资料
- (void) dataSourceRequestSubmitMessage
{

    Reachability *reach = [Reachability reachabilityForInternetConnection];
    NetworkStatus status = [reach currentReachabilityStatus];
    
    if (![UIView NetFromStatus:status]) {
        NSLog(@"没有网络");
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

        [UIView showAlertMsg:@"网络连接已断开" andShowBgColor:[UIColor blackColor] andLabelTectColor:[UIColor whiteColor]];
        
        return;
    }
    else
    {
        
        NSString *strUrl = [NSString stringWithFormat:@"%@creditcard/add",MRAPI];
        
        NSDictionary *paras_addCard = @{
                                        @"memberid":[[NSUserDefaults standardUserDefaults] objectForKey:@"memberid"],
                                        @"name":self.dic_pathPersonInfo[@"name"],
                                        @"sex":self.dic_pathPersonInfo[@"sex"],
                                        @"brithday":self.dic_pathPersonInfo[@"brithday"],
                                        @"nationality":self.dic_pathPersonInfo[@"nationality"],
                                        @"educationlevel":self.dic_pathPersonInfo[@"educationlevel"],
                                        @"ismarriage":self.dic_pathPersonInfo[@"ismarriage"],
                                        @"cardtype":self.dic_pathPersonInfo[@"cardtype"],
                                        @"cardnum":self.dic_pathPersonInfo[@"cardnum"],
                                        @"cardtime":self.dic_pathPersonInfo[@"cardtime"],
                                        @"fzjg":self.dic_pathPersonInfo[@"fzjg"],
                                        @"mobile":self.dic_pathPersonInfo[@"mobile"],
                                        @"address":self.dic_pathPersonInfo[@"address"],
                                        @"postcode":self.dic_pathPersonInfo[@"postcode"],
                                        @"tel":self.dic_pathPersonInfo[@"tel"],
                                        @"email":self.dic_pathPersonInfo[@"email"],
                                        @"company":self.dic_pathPersonInfo[@"company"],
                                        @"department":self.dic_pathPersonInfo[@"department"],
                                        @"position":self.dic_pathPersonInfo[@"position"],
                                        @"companyxingzhi":self.dic_pathPersonInfo[@"companyxingzhi"],
                                        @"companyaddress":self.dic_pathPersonInfo[@"companyaddress"],
                                        @"companttel":self.dic_pathPersonInfo[@"companttel"],
                                        @"nianshouru":self.dic_pathPersonInfo[@"nianshouru"],
                                        @"companyage":self.dic_pathPersonInfo[@"companyage"],
                                        @"contactname":self.dic_pathPersonInfo[@"contactname"],
                                        @"contacttype":self.dic_pathPersonInfo[@"contacttype"],
                                        @"contacttel":self.dic_pathPersonInfo[@"contacttel"],
                                        @"contactmobile":self.dic_pathPersonInfo[@"contactmobile"],
                                        @"contactname1":self.dic_pathPersonInfo[@"contactname1"],
                                        @"contacttype1":self.dic_pathPersonInfo[@"contacttype1"],
                                        @"contacttel1":self.dic_pathPersonInfo[@"contacttel1"],
                                        @"contactmobile1":self.dic_pathPersonInfo[@"contactmobile1"],
                                        @"creditcardbankid":[[NSUserDefaults standardUserDefaults] objectForKey:@"creditcardbankid"],
                                        @"creditcardcardid":[[NSUserDefaults standardUserDefaults] objectForKey:@"creditcardcardid"],
                                        @"hometype":self.dic_pathPersonInfo[@"hometype"],
                                        @"homexingzhi":self.dic_pathPersonInfo[@"homexingzhi"],
                                    @"homexingprice":self.dic_pathPersonInfo[@"homexingprice"],
                                        @"carpp":self.dic_pathPersonInfo[@"carpp"],
                                        @"carprice":self.dic_pathPersonInfo[@"carprice"],
                                        @"carnum":self.dic_pathPersonInfo[@"carnum"],
                                        @"cartime":self.dic_pathPersonInfo[@"cartime"],
                                        @"isortherxyk":self.dic_pathPersonInfo[@"isortherxyk"],
                                        @"fakabank":self.dic_pathPersonInfo[@"fakabank"],
                                        @"quota":self.dic_pathPersonInfo[@"quota"]};
        
        
        
        
        [[HttpRequest shardWebUtil] postNetworkRequestURLString:strUrl parameters:paras_addCard success:^(id obj) {
            
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            NSLog(@"addCoard%@",obj);
            NSString *str_false = obj[@"error"];
            
            if (str_false.length==0) {
                SubmitSuccessfullyVC *submitSuccessView = [[SubmitSuccessfullyVC alloc] init];
                [self.navigationController pushViewController:submitSuccessView animated:NO];
            }
            else
            {
                [UIView showAlertMsg:str_false];
            }
            
        } fail:^(NSError *error) {
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            [UIView showAlertMsg:@"网络请求超时"];
            
        }];
    }
}

#pragma mark keyboardNotification

- (void)keyboardWillShow:(NSNotification*)notification{
    
    if (record_section==1) {
        CGRect _keyboardRect = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
        
        //如果self在键盘之下 才做偏移
        if ([self convertYToWindow:CGRectGetMaxY(self.tableView_fillInfo.frame)]>=_keyboardRect.origin.y)
        {
            //没有偏移 就说明键盘没出来，使用动画
            if (self.view.frame.origin.y== self.tableView_fillInfo.frame.origin.y) {
                
                [UIView animateWithDuration:0.3 animations:^{
                    self.view.frame = CGRectMake(0, -_keyboardRect.size.height+[self getHeighOfWindow]-CGRectGetMaxY(self.view.frame), kScreenWidth, kScreenHeight);
                }];
            }
            else
            {
                self.view.frame = CGRectMake(0,140, kScreenWidth, kScreenHeight);
            }
        }
    }
}

- (void)keyboardWillHide:(NSNotification*)notification{
    
    [UIView animateWithDuration:0.3 animations:^{
        self.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    }];
}

#pragma  mark ConvertPoint
//将坐标点y 在window和superview转化  方便和键盘的坐标比对
-(float)convertYFromWindow:(float)Y
{
    AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    CGPoint o = [appDelegate.window convertPoint:CGPointMake(0, Y) toView:self.view];
    return o.y;
    
}
-(float)convertYToWindow:(float)Y
{
    AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    CGPoint o = [self.view convertPoint:CGPointMake(0, Y) toView:appDelegate.window];
    return o.y;
    
}
-(float)getHeighOfWindow
{
    AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    return appDelegate.window.frame.size.height;
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
